package scala.maven;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import java.util.ArrayList;
import java.util.List;

/**
 * Run a Scala class using the Scala runtime
 *
 * @goal run
 * @requiresDependencyResolution compile
 * @phase process-sources
 */
public class ScalaRunMojo extends ScalaMojo {

    /**
     * @parameter expression="${mainClass}"
     * @required
     */
    protected String mainClass;

    public void execute() throws MojoExecutionException, MojoFailureException {
        super.execute();
        ArrayList<String> command = new ArrayList<String>();
        command.add(javaBin);
        //see ScalaMojo
        super.addMemoryOptions(command);
        command.add("-classpath");
        command.add(getClassPath(classpathElements));
        command.add(mainClass);
        runCommand(command.toArray(new String[0]));
    }
}
